package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.anno.AuthLogin;
import com.atguigu.tingshu.common.annotation.Log;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	// 	/api/album/trackInfo/findUserTrackPage/{page}/{limit}
	@PostMapping("/findUserTrackPage/{page}/{limit}")
	public Result<IPage<TrackListVo>> findUserTrackPage(@PathVariable("page") Integer pageNo,
														@PathVariable("limit") Integer pageSize,
														@RequestBody TrackInfoQuery trackInfoQuery) {
		return Result.ok(trackInfoService.findUserTrackPage(pageNo, pageSize, trackInfoQuery));
	}

	// 	/api/album/trackInfo/uploadTrack
	@PostMapping("uploadTrack")
	public Result<UploadTrackVo> uploadTrack(MultipartFile file) {
		return Result.ok(trackInfoService.uploadTrack(file));
	}

	// 	/api/album/trackInfo/saveTrackInfo
	@PostMapping("saveTrackInfo")
	public Result<Object> saveTrackInfo(@RequestBody @Validated TrackInfoVo trackInfoVo) {
		trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}

	// 	/api/album/trackInfo/getTrackInfo/{id}
	@GetMapping("getTrackInfo/{id}")
	public Result<TrackInfo> getTrackInfo(@PathVariable("id") Long trackId) {
		return Result.ok(trackInfoService.getById(trackId));
	}

	// 	/api/album/trackInfo/updateTrackInfo/{id}
	@PutMapping("updateTrackInfo/{id}")
	public Result<Object> updateTrackInfo(@PathVariable("id") Long trackId,
										  @RequestBody TrackInfoVo trackInfoVo) {
		trackInfoService.updateTrackInfo(trackId, trackInfoVo);
		return Result.ok();
	}

	// 	/api/album/trackInfo/removeTrackInfo/{id}
	@DeleteMapping("removeTrackInfo/{id}")
	public Result<Object> removeTrackInfo(@PathVariable("id") Long trackId) {
		trackInfoService.removeTrackInfo(trackId);
		return Result.ok();
	}

	// 	/api/album/trackInfo/findAlbumTrackPage/{albumId}/{page}/{limit}
	@AuthLogin
	@GetMapping("/findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage(@PathVariable Long albumId,
															  @PathVariable("page") Integer pageNo,
															  @PathVariable("limit") Integer pageSize) {
		return Result.ok(trackInfoService.findAlbumTrackPage(albumId, pageNo, pageSize));
	}

	// /api/album/trackInfo/getTrackStatVo/{trackId}
	@GetMapping("/getTrackStatVo/{trackId}")
	public Result<TrackStatVo> getTrackStatVo(@PathVariable Long trackId) {
		return Result.ok(trackInfoService.getTrackStatVo(trackId));
	}

	// 	/api/album/trackInfo/findUserTrackPaidList/{trackId}
	@AuthLogin
	@GetMapping("/findUserTrackPaidList/{trackId}")
	public Result<List<TrackPayVo>> findUserTrackPaidList(@PathVariable Long trackId) {
		return Result.ok(trackInfoService.findUserTrackPaidList(trackId));
	}

	// 	/findPaidTrackInfoList/{trackId}/{trackCount}
	@AuthLogin
	@GetMapping("/findPaidTrackInfoList/{trackId}/{trackCount}")
	public Result<List<TrackInfo>> findPaidTrackInfoList(@PathVariable Long trackId,@PathVariable Integer trackCount){
		return Result.ok(trackInfoService.findPaidTrackInfoList(trackId,trackCount));
	}
}

